package com.xysoft.framework.interceptor;

import java.lang.reflect.Method;
import java.util.Date;

import org.springframework.aop.MethodBeforeAdvice;

import com.xysoft.framework.entity.BusinessEntity;

public class BeforeSaveEntityInterceptor implements MethodBeforeAdvice {

	@Override
	public void before(Method method, Object[] args, Object target) throws Throwable {
		Object entity = args[0];
		
		if(entity instanceof BusinessEntity) {
			BusinessEntity businessEntity = (BusinessEntity) entity;
			if(businessEntity.getCreatedDate() == null) {
				businessEntity.setCreatedDate(new Date());
			}
			if(businessEntity.getLastModified()==null) {
				businessEntity.setLastModified(new Date());
			}
		}
	}

}
